package {
import flare.animate.TransitionEvent;
import flare.animate.Transitioner;
import flare.demos.Layouts;
import flare.demos.util.LinkGroup;
import flare.display.LineSprite;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;

import flash.text.TextField;

import mx.controls.Button;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.Operation;
import mx.rpc.soap.WebService;
import mx.collections.ArrayList

[SWF(width="1000",height="700",backgroundColor="#ffffff", frameRate="30")]
public class Test extends Sprite
{
    private var _demoLayout:Layouts;
    private var _demo:Sprite;
    private var _line:LineSprite;
    private var ws:WebService;
    private var button:Button = new Button();
    private var textField:TextField = new TextField();

    public function Test()
    {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        stage.addEventListener(Event.RESIZE, onResize);
        button = new Button();
        textField.text = "1";
        textField.width = 2000;

        this.addChild(textField);
        //this.addChild(button)

        //showStartLayout()
        //onResize();

        textField.text = "2";
        callSearchURL("http://localhost:6890/CrawlerService?WSDL", 5, 5, 1000)
    }

    public function callSearchURL(wsdl:String, threads:int, deep:int, time:int):void {
        ws = new WebService();
        ws.loadWSDL(wsdl);
        ws.useProxy = true;
        ws.searchByURL.addEventListener("result", searchResultHandler);
        ws.addEventListener("fault", faultHandler);
        ws.searchByURL(threads, deep, time);
    }

    public function searchResultHandler(event:ResultEvent):void {
        var retStr:String = event.result as String;

        //Do something.
    }

    public function faultHandler(event:FaultEvent):void {
        textField.text = event.toString();
        //deal with event.fault.faultString, etc
    }


    private function showStartLayout():void
    {
        addChild(_line = new LineSprite());

        _demo = new Sprite();
        addChild(_demo);

        _demoLayout = new Layouts();
        _demo.alpha = 0;
        _demo.addChild(_demoLayout as Sprite);

        var t:Transitioner = new Transitioner(1);
        t = new Transitioner(1);
        t.delay = 0.5;
        t.addEventListener(TransitionEvent.START,
                function(evt:Event):void {
                    onResize();
                    _demoLayout.start();
                }
                );
        t.$(_demo).alpha = 1;
        t.play();
    }

    private function onResize(event:Event = null):void
    {
        _line.x2 = stage.stageWidth;
        _demoLayout.bounds = new Rectangle(0, _line.y,
                stage.stageWidth, stage.stageHeight - (_line.y));
    }

} // end of class demos
}